﻿''' <summary>
''' Represents an event log entry.
''' </summary>
''' <remarks>
''' Objects of this class are used by the event log collector. They represent an 
''' event log that is to be scanned.
''' </remarks>
Public Class EventLogEntry

    ''' <summary>
    ''' Machine name where log resides (. or empty for local machine).
    ''' </summary>
    ''' <remarks></remarks>
    Protected m_machine As String

    ''' <summary>
    ''' Log name.
    ''' </summary>
    ''' <remarks></remarks>
    Protected m_name As String

    ''' <summary>
    ''' Array with event log types to include.
    ''' </summary>
    ''' <remarks></remarks>
    Protected m_type() As String

    ''' <summary>
    ''' Number of event log entries to collect.
    ''' </summary>
    ''' <remarks></remarks>
    Protected m_number As Integer

    ''' <summary>
    ''' Get/set machine name where log resides.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Machine() As String
        Get
            Return m_machine
        End Get
        Set(ByVal value As String)
            m_machine = value
        End Set
    End Property

    ''' <summary>
    ''' Get/set event log name.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Name() As String
        Get
            Return m_name
        End Get
        Set(ByVal value As String)
            m_name = value
        End Set
    End Property

    ''' <summary>
    ''' Get/set event log types to include in the report.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Type() As String()
        Get
            Return m_type
        End Get
        Set(ByVal value As String())
            m_type = value
        End Set
    End Property

    ''' <summary>
    ''' Get/set the number of event log entries to collect.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Number() As Integer
        Get
            Return m_number
        End Get
        Set(ByVal value As Integer)
            m_number = value
        End Set
    End Property

    ''' <summary>
    ''' Default class constructor.
    ''' </summary>
    ''' <param name="machine">Machine name.</param>
    ''' <param name="name">Log name.</param>
    ''' <param name="type">Event log types (comma-separated).</param>
    ''' <param name="number">Number of entries.</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal machine As String, ByVal name As String, ByVal type As String, ByVal number As String)
        m_machine = machine
        m_name = name
        'Split the entries.
        type = type.Replace(" ", "")
        m_type = type.Split(","c)
        'If all is specified...
        If number.ToLower() = "all" Then
            'Set to maximum
            m_number = Integer.MaxValue
        Else
            m_number = Convert.ToInt32(number)
        End If
    End Sub

    ''' <summary>
    ''' Determines whether we're examining the local machine.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function isLocalMachine() As Boolean
        Return (m_machine Is Nothing) OrElse (m_machine = "")
    End Function

    ''' <summary>
    ''' Returns a proper machine name.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getMachineName() As String
        If isLocalMachine() Then
            Return "."
        Else
            Return m_machine
        End If
    End Function

    ''' <summary>
    ''' Determines whether we care about a particular entry.
    ''' </summary>
    ''' <param name="typeStr">Type of entry to examine.</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function isTypeIncluded(ByVal typeStr As String) As Boolean
        For i As Integer = 0 To m_type.GetUpperBound(0)
            If m_type(i) = typeStr Then
                Return True
            End If
        Next
        Return False
    End Function

End Class
